package com.ly.cloud.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ly.cloud.dto.CampusBasicInfoDto;
import com.ly.cloud.service.CampusBasicInfoService;
import com.ly.cloud.vo.CampusBasicInfoTyVo;
import com.ly.cloud.vo.CampusBasicInfoVo;
import com.ly.cloud.web.utils.WebResponse;

/**
 * Description:该控制器操作校区基本信息
 * @author luhuacong
 * @date: 2018/12/6
 */
@RestController
@RequestMapping("/campusInfo")
public class CampusInfoController {

	@Resource
	private CampusBasicInfoService campusBasicInfoService;
	
	/**
	 * Description:添加校区信息
	 * @param 条件封装对象
	 * @return  WebResponse<Boolean>
	 * @author luhuacong
	 * @date: 2018/12/13
	 */
	@RequestMapping(value="/insert",method = RequestMethod.POST)
	public WebResponse<Boolean> insertDetail(@RequestHeader(required=false,value = "loginUserName") String loginUserName,@RequestBody CampusBasicInfoDto dto) {
		boolean rs = campusBasicInfoService.insertCampusInfo(dto, loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/** 
	 * Method Name:  updateCampusInfo
	 * Description:  
	 * 修改校区基本信息
	 * @param dto
	 * @param loginUserName 当前登录人
	 * @return boolean
	 * @author luhuacong
	 * @date: 2018年12月13日
	 */
	@RequestMapping(value = "updateCampusInfo", method = RequestMethod.POST)
	public WebResponse<Boolean> updateShcoolInfo(@RequestBody CampusBasicInfoDto dto,@RequestHeader(required=false,value = "loginUserName") String loginUserName) {
		boolean isUpdate = campusBasicInfoService.updateCampusInfo(dto, loginUserName);
		return new WebResponse<Boolean>().success(isUpdate);
	}
	
	/** 
	 * Method Name:  deleteById
	 * Description:  
	 * 删除校区基本信息
	 * @return boolean 是否删除成功
	 * @author luhuacong
	 * @date: 2018年12月13日
	 */
	@RequestMapping(value = "delete/{xqdm}", method = RequestMethod.POST)
	public WebResponse<Boolean> deleteById(@PathVariable("xqdm") String xqdm) {
		boolean isDelete = campusBasicInfoService.deleteById(xqdm);
		return new WebResponse<Boolean>().success(isDelete);
	}
	
	/** 
	 * Method Name:  selectCampusList
	 * Description:  
	 * 查询学校校区
	 * @param xqmc 校区名称
	 * @return List<CampusBasicInfoVo>
	 * @author luhuacong
	 * @date: 2018年12月13日
	 */
	@RequestMapping(value = "selectCampusList", method = RequestMethod.GET)
	public WebResponse<List<CampusBasicInfoVo>> selectCampusList(@RequestParam(required=false) String xqmc) {
		List<CampusBasicInfoVo> vo = campusBasicInfoService.selectCampusList(xqmc);
		return new WebResponse<List<CampusBasicInfoVo>>().success(vo);
	}
	
	/** 
	 * Method Name:  selectCampusList
	 * Description:  
	 * 查询学校校区，用于下拉列表。若jxlmc不为空，则根据教学楼号查询拥有该教学楼名称的校区
	 * 					  若jxlmc为空，则查询全部校区
	 * @param jxlh 教学楼名称
	 * @return List<CampusBasicInfoTyVo>
	 * @author luhuacong
	 * @date: 2018年12月13日
	 */
	@RequestMapping(value = "selectCampusListTy", method = RequestMethod.GET)
	public WebResponse<List<CampusBasicInfoTyVo>> selectCampusListTy(@RequestParam(required=false) String jxlmc) {
		List<CampusBasicInfoTyVo> vo = campusBasicInfoService.selectCampusListTy(jxlmc);
		return new WebResponse<List<CampusBasicInfoTyVo>>().success(vo);
	}
}
